package com.ymttest.database.mongo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import com.ymt.core.tool.Logger;
import com.ymt.database.MongoDBDriver;

/************************************************************************************
 * @File name :ProductBasicInfo.java
 * @Author : xujiewei
 * @Date : 2016年6月28日
 * @Copyright : 洋码头
 * 商品合库 新库
 ************************************************************************************/
public class ProductBasicInfoWapper {
	MongoDBDriver mdd = YmtMongoDriverFactroy.getInstance_YmtProductDBdriver("ProductBasicInfo");

	    public ProductBasicInfoWapper(){
	    }
	    
		@Deprecated
	    public Map<String, Object> getProductId(String productId) throws Exception {
	        Map<String, Object> scmb = new HashMap<String, Object>();
	        ArrayList<Map> list = mdd.selectPartLimitToMap("{\"ProductId\":\"" + productId + "\"}",
	                "{'_id':1,'AcceptReturn':1, 'AddTime':1, 'BondedArea':1, 'BrandEnName':1, 'BrandId':1, 'BrandName':1, 'CatalogType':1, "
	                + "'CategoryId':1, 'CategoryName':1, 'DeliveryMethod':1, 'DeliveryTemplateId':1, 'Freight':1, 'IsMallProduct':1, 'LastRefreshTime':1, 'LimitNum':1, "
	                + "'LimitNumStartTime':1, 'LogisticsType':1, 'MainPicUrl':1, 'MasterCategoryId':1, 'MasterCategoryName':1, 'MaxCatalogPrice':1, "
	                + "'MinCatalogPrice':1, 'Name':1, 'PicList':1, 'ProdId':1, 'ProductCountry':1, 'ProductId':1, 'ProductSubTitle':1, 'SellerCountry':1, "
	                + "'SellerId':1, 'SellerName':1, 'Status':1, 'TariffType':1, 'ThirdCategoryId':1, 'ThirdCategoryName':1, 'ValidStart':1, 'ValidEnd':1, 'Weight':1, 'Country':1, 'Flag':1,'isTop':1}", 1, "{'AddTime':-1}");
	        try {
	            if (list.size() > 0) {
	                scmb = list.get(0);
	                return scmb;
	            }
	        } catch (Exception e) {
	            Logger.debug("err data productId:" + productId);
	            e.printStackTrace();
	        }
	        return null;
	    }
	    
	    
	    
	    public Map<String, Object> getByProductId(String productId) throws Exception {
	        Map<String, Object> scmb = new HashMap<String, Object>();
	        ArrayList<Map> list = mdd.selectPartLimitToMap("{\"ProductId\":\"" + productId + "\"}",1);
	             try {
	            if (list.size() > 0) {
	                scmb = list.get(0);
	                return scmb;
	            }
	        } catch (Exception e) {
	            Logger.debug("err data productId:" + productId);
	            e.printStackTrace();
	        }
	        return null;
	    }
	    
	    
		public int getCountByProductId(String productId) throws Exception{
			return mdd.selectPartLimitToMap("{\"ProductId\":\"" + productId + "\"}",50).size();
		}
		
	    
	    public static void main(String[] args) throws Exception {
			System.out.println(new ProductBasicInfoWapper().getCountByProductId("6b299ad7-9e3f-48d8-b502-2405b41c374c"));
		}
}
